Skip to content

Add stubs for httpretty - #16048

Merged
srittau merged 14 commits into
python:mainfrom
adamtheturtle:agent/add-httpretty-stubs
Aug 20, 2026
Merged

Add stubs for httpretty#16048
srittau merged 14 commits into
python:mainfrom
adamtheturtle:agent/add-httpretty-stubs

Conversation

@adamtheturtle

@adamtheturtle adamtheturtle commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Adds type stubs for HTTPretty 1.1.4.

Related: #16047.

@adamtheturtle
adamtheturtle marked this pull request as ready for review July 20, 2026 13:29
@github-actions

This comment has been minimized.

@donbarbos donbarbos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I noted a few moments:

Comment thread stubs/httpretty/httpretty/__init__.pyi Outdated
Comment thread stubs/httpretty/httpretty/core.pyi Outdated
Comment thread stubs/httpretty/httpretty/http.pyi Outdated
Comment thread stubs/httpretty/httpretty/http.pyi Outdated
Comment thread stubs/httpretty/httpretty/core.pyi Outdated
Comment thread stubs/httpretty/httpretty/core.pyi Outdated
@property
def host(self) -> str: ...
def parse_querystring(self, qs: str) -> dict[str, list[str]]: ...
def parse_request_body(self, body: str) -> Any: ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add some explanatory comments:

Suggested change
def parse_request_body(self, body: str) -> Any: ...
def parse_request_body(self, body: str) -> Any: ... # Any object can be returned if deserialization is successful

Comment thread stubs/httpretty/httpretty/core.pyi Outdated
Comment thread stubs/httpretty/httpretty/version.pyi Outdated
@@ -0,0 +1 @@
version: str

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version: str
from typing import Final
version: Final[str]

Comment thread stubs/httpretty/httpretty/core.pyi
Comment thread stubs/httpretty/httpretty/__init__.pyi Outdated
)
from .errors import HTTPrettyError as HTTPrettyError, UnmockedError as UnmockedError

__version__: str

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
__version__: str
__version__: Final[str]

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

adamtheturtle and others added 10 commits August 20, 2026 11:55
Co-authored-by: Semyon Moroz <donbarbos@proton.me>
Co-authored-by: Semyon Moroz <donbarbos@proton.me>
Co-authored-by: Semyon Moroz <donbarbos@proton.me>
Co-authored-by: Semyon Moroz <donbarbos@proton.me>
Co-authored-by: Semyon Moroz <donbarbos@proton.me>
Co-authored-by: Semyon Moroz <donbarbos@proton.me>
Import Final and define _HTTPMethod/_WritableFileobj so mypy/stubtest
pass; apply reviewer suggestions for Protocols and comments.

Co-authored-by: Cursor <cursoragent@cursor.com>
@adamtheturtle
adamtheturtle force-pushed the agent/add-httpretty-stubs branch from f015aa0 to 37cbe71 Compare August 20, 2026 10:55
HttpBaseClass already marks them Final; subclass overrides fail mypy.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

This comment has been minimized.

@adamtheturtle

Copy link
Copy Markdown
Contributor Author

Addressed review feedback (Final imports, _HTTPMethod alias, _WritableFileobj Protocol, comments) and fixed mypy/stubtest failures. CI is green on latest main — ready for maintainer merge.

@srittau srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'm not sure that we need the tests. In typeshed, we only add regression tests for functions and classes which are known to have caused complex problems in the past, or where stubs are difficult to get right. 100% test coverage for typeshed is neither necessary nor desirable, as it would lead to code duplication.

See tests/REGRESSION.md for more information.

A few smaller suggestions below.

Comment thread stubs/httpretty/httpretty/core.pyi Outdated
Comment on lines +196 to +201
@overload
def httprettified(test: Callable[_P, Any]) -> Callable[_P, Any]: ...
@overload
def httprettified(
test: None = None, allow_net_connect: bool = True, verbose: bool = False
) -> Callable[[Callable[_P, Any]], Callable[_P, Any]]: ...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the return value is passed back unchanged:

Suggested change
@overload
def httprettified(test: Callable[_P, Any]) -> Callable[_P, Any]: ...
@overload
def httprettified(
test: None = None, allow_net_connect: bool = True, verbose: bool = False
) -> Callable[[Callable[_P, Any]], Callable[_P, Any]]: ...
@overload
def httprettified(test: Callable[_P, _R) -> Callable[_P, _R]: ...
@overload
def httprettified(
test: None = None, allow_net_connect: bool = True, verbose: bool = False
) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]: ...

(Also needs a type var definition _R = TypeVar("_R") at the top of the file.)

Comment thread stubs/httpretty/httpretty/http.pyi Outdated
METHODS: tuple[_HTTPMethod, ...]

def parse_requestline(s: str) -> tuple[str, str, str]: ...
def last_requestline(sent_data: Sequence[_T]) -> _T | None: ...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is sent to reversed, we can use a protocol here:

Suggested change
def last_requestline(sent_data: Sequence[_T]) -> _T | None: ...
def last_requestline(sent_data: SupportsLenAndGetItem[_T]) -> _T | None: ...

(SupportsLenAndGetItem needs to be imported from _typeshed.)

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau
srittau merged commit 3c8c561 into python:main Aug 20, 2026
74 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants